package com.wise.service.portal.content.pagedecorates;

import cn.hutool.core.collection.CollectionUtil;
import com.wise.entities.content.Decorate;
import com.wise.framework.annotations.*;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import com.wise.framework.summer.BasicSummer;
import com.wise.framework.validation.Precondition;
import com.wise.summer.v1.portal.content.pagedecorates.ListPageDecorates;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.wise.model.content.ContentErrMsgs.Err_000500000026;

@Service
@SummerService
public class ListPageDecoratesService implements SummerServiceBean<ListPageDecorates> {

	@Override
	public void sum(ListPageDecorates summer) {
		Precondition.checkState(CollectionUtil.isNotEmpty(summer.getIdList()), Err_000500000026);

		SqlSelect sqlSelect = SqlSelect.selec("*")
				.fromClassName(Decorate.class)
				.in(Decorate._id, summer.getIdList());

		List<Decorate> decorateList = DaoList.s(Decorate.class, sqlSelect);

		Map<String, Decorate> decorateMap = decorateList.stream()
				.collect(Collectors.toMap(Decorate::getId, it -> it));

		summer.setSummerResult(decorateMap);
	}
}
